package com.yk.filedownload.ConfigIt;

import org.json.JSONObject;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

/**
 * Project Name:cykfiledownload
 * File Name:Configuration
 * Package Name:com.yk.filedownload.ConfigIt
 * Date:2017\12\7 0007
 * Author:dengtianjia
 * Description:
 * Copyright (c) 2017, 重庆云凯科技有限公司 All Rights Reserved.
 */
public class Configuration {
    /**
     * 模块的配置信息类
     */

    /**
     * kafka集群地址
     */
    public static String KAFKA_URL;
    /**
     * kafka单词允许拉取的最大消息数
     */
    public static int KAFKA_MAX_CONSUMER_NUM = 14;
    /**
     *拉取文件下载的主题
     */
    public static String DOWNLOAD_FILE_URL_TOPIC;
    /**
     * 数据头文件发送主题
     */
    public static String FILE_HEADER_PUSH_TOPIC;

    /**************************线程池配置**************************************
     *
     *核心线程池的大小,允许的最大线程数
     */
    public static int CORE_POOL_SIZE = 8;
    /**
     *线程池的最大线程数
     */
    public static int MAXIMIMPOOLSIZE = 10;

    /**
     *空闲线程的最长保留时间
     */
    public static long KEEP_ALIVE_TIME = 60000;

    /******************************************************************
     *
     *开启多线程下载的文件大小阈值
     */
    public static int MUIL_FILEDOWNLOAD_THRESHOLD = 10*1024*1024;
    /**
     * 线程的最小下载速率，小于该速率，此下载线程会被中断，url连接抛弃至低速下载url连接队列中  单位kb
     */
    public static double MIN_DOWNLOAD_RATE_OF_THREAD =   0.0;

    /**
     *redis集群地址
     */
    public static String REDIS_CLUSTERS ="10.0.104.20:7000,10.0.104.21:7003,10.0.104.22:7006,10.0.104.20:7001,10.0.104.21:7004,10.0.104.22:7007,10.0.104.20:7002,10.0.104.21:7005,10.0.104.22:7008";

    /**
     *系统运行状态监控信息存储在redis上的key
     */
    public static String STATUS_MONITORING_OF_FILEDOWN_KEY_IN_REDIS = "FILE_DOWNLOAD_STATUS";

    /**
     *redis集群允许创建的最大连接数
     */
    public static int REDIS_MAXTOTAL = 8;
    /**
     *redis集群允许的最大空闲连接数
     */
    public static int REDIS_MAXIDLE = 3;
    /**
     *redis集群获取redis运行实例的最大等待时间
     */
    public static int REDIS_MAXWAITMILLIS = 2000;

    /**
     *允许的最大组装线程
     *
     */
    public static int COMBIN_MAX_THREAD_NUM = 5;


    static {
        try {
            configInit("");
        }catch (Exception e){
            e.printStackTrace();
        }
    }


    private static void configInit(String filedown_url) throws Exception{
//        String result = null;
//        StringBuffer sbf = new StringBuffer();
//        URL url = new URL(filedown_url);
//        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
//        connection.connect();
//        InputStream in = connection.getInputStream();
//        BufferedReader reader = new BufferedReader(new InputStreamReader(in, "UTF-8"));
//        String strRead = null;
//        while ((strRead = reader.readLine()) != null) {
//            sbf.append(strRead);
//        }
//        reader.close();
//        result = sbf.toString();
//        JSONObject config = new JSONObject(result);
    }




}
